export const Base = {
  data() {
    return {
      total: 0,
      pagesize: 5,
      page: 1,
      name: '',
      modal1: false,
      id: ''

    }
  },
  methods: {
    edit(params) {
      this.modal1 = true;
      this.axios({
        method: 'get',
        url: `http://localhost:3000/${this.module}/data/${params.row._id}`
      }).then(res => {
        console.log(res.data)
        this.formValidate = res.data;
        this.id = res.data._id
      })
    },
    remove(params) {
      console.log(params);
      this.$Modal.confirm({
        title: 'Delete',
        content: '<p>您确定要删除吗</p>',
        onOk: () => {
          this.axios({
            method: 'delete',
            url: `http://localhost:3000/${this.module}/data/${params.row._id}`
          }).then(() => {
            console.log('.....');
            this.getlist();
          })
        },
        onCancel: () => {
          this.$Message.info('Cancel delete');
        }
      });

    },
    getlist() {
      this.axios({
        method: 'post',
        url: `http://localhost:3000/${this.module}/list`,
        data: {
          page: this.page,
          rows: this.pagesize,
          condition: this.name
        }
      }).then(data => {
        this.userdata = data.data.rows;
        this.total = data.data.total
      })
    },
    onChangePage(page) {
      this.page = page;
      this.getlist()
    },
    onpagesizechange(pageSize) {
      this.pagesize = pageSize;
      this.getlist()
    },
    search() {
      console.log('----->')
      this.getlist()
    },
    handleSubmit(name) {
      if (this.id.length != 0) {
        //修改操作
        this.axios({
          url: `http://localhost:3000/${this.module}/data/${this.id}`,
          method: 'put',
          data: this.formValidate
        }).then(res => {
          this.modal1 = false;
          this.getlist();
          this.id = '';
          this.$refs[name].resetFields();
        })
      } else {
        console.log(this.formValidate)
        this.axios({
          url: `http://localhost:3000/${this.module}/data`,
          method: 'post',
          data: this.formValidate
        }).then(() => {
          this.modal1 = false;
          this.$refs[name].resetFields();
          this.getlist()
        })
      }
    },
    handleReset(name) {
      this.$refs[name].resetFields();
    }


  },
  mounted() {
    this.getlist()
  }
}
